import time

from common.localUtil import LocalUtil
from common.yamlUtil import YamlUtil
from selenium import webdriver
from selenium.webdriver.common.by import By


class LoginUtil:

    # 构建方法
    def __init__(self, wd):
        self.wd = wd
        self.data = YamlUtil("data.yaml").read_yaml()
        self.conf = YamlUtil("local.yaml").read_yaml()
        self.local = LocalUtil(wd)

    # 登录
    def login_eip(self):
        time.sleep(3)
        # self.local.wait_for_page_loaded(10)
        work_number_input = self.wd.find_element(By.NAME, "UserName")
        # work_number_input.send_keys(f"{self.data['work_number']}")
        work_number_input.send_keys('JX088074')
        password = self.wd.find_element(By.NAME, "Password")
        # password.send_keys(f"{self.data['password']}")
        password.send_keys('3035361506@Wsjlt')
        time.sleep(2)
        login = self.wd.find_element(By.XPATH, f"{self.conf['login']}")
        login.click()
        self.enter_order_page()

    # 进入到提单页面
    def enter_order_page(self):
        # self.local.wait_for_page_loaded()
        time.sleep(2)
        process = self.local.wait_for_element(By.XPATH, f"{self.conf['process']}")
        process.click()
        time.sleep(4)

        # 切换到流程frame
        self.wd.switch_to.frame('iframe2593754b-59ab-aef9-633d-4543f22f420a')

        # 点击人事表单
        people_form = self.wd.find_element(By.XPATH, f"{self.conf['people_order']}")
        time.sleep(1)
        people_form.click()


